package com.scm.servlet.pomain;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.scm.page.Page;
import com.scm.model.Pomain;
import com.scm.service.PomainService;

/**
 * Servlet implementation class PomainReportDetailServlet
 */
@WebServlet("/main/pomain/PomainReportDetail")
public class PomainReportDetailServlet extends HttpServlet {
	private static final long serialVersionUID = -1098864275927277947L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String currentPageStr = req.getParameter("currentPage");
		int currentPage = 1;//默认当前页码为第一页
		try{
			currentPage = Integer.parseInt(currentPageStr);
		}catch(NumberFormatException e){
			currentPage = 1;//参数不是数字或者没有该参数时，默认访问第一页
		}
		
		String month = req.getParameter("month");
		Map<String, String> queryCondition = new HashMap<String, String>();
		queryCondition.put("type", "-1");
		queryCondition.put("startDate", month+"-01");
		queryCondition.put("endDate", month+"-31");
		
		try {
			Page<Pomain> page = new PomainService().selectPage(currentPage,queryCondition);
			req.setAttribute("page", page);
			req.getRequestDispatcher("/gztm/pomain_report_detail_layer.jsp").forward(req, resp);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

}
